package t327.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import t327.pojo.*;
import t327.pojo.MaterialStoreRel;
import t327.pojo.Materials;
import t327.pojo.Store;
import t327.pojo.font.LuiTableEntity;
import t327.pojo.font.MaterialsAddWareHouseFont;
import t327.pojo.views.*;
import t327.service.iter.IWareHouseService;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("warehouse")
public class WareHouseController {
    @Autowired
    private IWareHouseService wareHouseService;
    @RequestMapping("queryAllWarehouseStoreAreaBatchView")
    @ResponseBody
    public LuiTableEntity queryAllWarehouseStoreAreaBatchView(@RequestParam(value = "page") Integer pageNum, @RequestParam(value = "limit")Integer pageSize){
        List<WarehouseStoreAreaBatchView> warehouseStoreAreaBatchViews = wareHouseService.queryAllWarehouseStoreAreaBatchView();
        LuiTableEntity luiTableEntity = new LuiTableEntity<WarehouseStoreAreaBatchView>();
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<WarehouseStoreAreaBatchView> menuPageInfo = new PageInfo<>(warehouseStoreAreaBatchViews);
        List<WarehouseStoreAreaBatchView> clients = menuPageInfo.getList();
        long total = menuPageInfo.getTotal();
        if (clients != null && clients.size() > 0) {
            luiTableEntity.setCode("0");
            luiTableEntity.setMsg("查询成功");
            luiTableEntity.setCount(total);
            luiTableEntity.setData(clients);
        } else {
            luiTableEntity.setCode("203");
            luiTableEntity.setMsg("查询失败");
        }
        return luiTableEntity;
    }

    @RequestMapping("queryByName")
    @ResponseBody
    public LuiTableEntity queryByName(@RequestParam(value = "page") Integer pageNum, @RequestParam(value = "limit")Integer pageSize, @RequestParam(value = "searchValue")String searchValue){
        List<WarehouseStoreAreaBatchView> warehouseStoreAreaBatchViews = wareHouseService.queryByName(searchValue);
        LuiTableEntity luiTableEntity = new LuiTableEntity<WarehouseStoreAreaBatchView>();
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<WarehouseStoreAreaBatchView> menuPageInfo = new PageInfo<>(warehouseStoreAreaBatchViews);
        List<WarehouseStoreAreaBatchView> clients = menuPageInfo.getList();
        long total = menuPageInfo.getTotal();
        if (clients != null && clients.size() > 0) {
            luiTableEntity.setCode("0");
            luiTableEntity.setMsg("查询成功");
            luiTableEntity.setCount(total);
            luiTableEntity.setData(clients);
        } else {
            luiTableEntity.setCode("203");
            luiTableEntity.setMsg("查询失败");
        }
        return luiTableEntity;
    }
    @RequestMapping("togetAllWarehouseStoreAreaBatchView")
    @ResponseBody
    public List<WarehouseStoreAreaBatchView> getAllWarehouseStoreAreaBatchView() {
        return wareHouseService.getAllWarehouseStoreAreaBatchView();
    }
    @RequestMapping("queryAllStoreArea")
    public List<StoreArea> queryAllStoreArea(){
        return wareHouseService.queryAllStoreArea();
    }

    @RequestMapping("queryAllColor")
    public List<Color> queryAllColor() {
        return wareHouseService.queryAllColor();
    }
    @RequestMapping("queryAllWarehouse")
    public List<Warehouse> queryAllWarehouse() {
        return wareHouseService.queryAllWarehouse();
    }
    @RequestMapping("queryAllMaterials")
    public List<Materials> queryAllMaterials() {
        return wareHouseService.queryAllMaterials();
    }
    @RequestMapping("queryAllMaterialKind")
    public List<MaterialKind> queryAllMaterialKind() {
        return wareHouseService.queryAllMaterialKind();
    }
    @RequestMapping("queryAllQuality")
    public List<Quality> queryAllQuality() {
        return wareHouseService.queryAllQuality();
    }
    @RequestMapping("addMaterialsAndBatch")
    public HashMap<String,String> addMaterialsAndBatch(@RequestBody MaterialsAddWareHouseFont materialsAddWareHouseFont){
        return wareHouseService.addMaterialsAndBatch(materialsAddWareHouseFont);
    }

    @RequestMapping("addMaterials")
    @ResponseBody
    public int addMaterials(@RequestBody Materials materials) {
        return wareHouseService.addMaterials(materials);
    }

    @RequestMapping("addMaterialStoreRelchu")
    @ResponseBody
    public int addMaterialStoreRelchu(@RequestBody MaterialStoreRel materialStoreRel) {
        return wareHouseService.addMaterialStoreRelchu(materialStoreRel);
    }

    @RequestMapping("addStorechu")
    @ResponseBody
    public int addStorechu(@RequestBody Store store) {
        return wareHouseService.addStorechu(store);
    }
    @RequestMapping("addMaterialStoreRelRu")
    @ResponseBody
    public int addMaterialStoreRelRu(@RequestBody MaterialStoreRel materialStoreRel) {
        return wareHouseService.addMaterialStoreRelRu(materialStoreRel);
    }

    @RequestMapping("addStoreRu")
    @ResponseBody
    public int addStoreRu(@RequestBody Store store) {
        return wareHouseService.addStoreRu(store);
    }

    @RequestMapping("getAllMaterials")
    @ResponseBody
    public List<Materials> getAllMaterials() {
        return wareHouseService.getAllMaterials();
    }

    //查询订单列表
    @RequestMapping("getSubMaterialViewAll")
    @ResponseBody
    public LuiTableEntity getSubMaterialViewAll(@RequestParam(value = "page") Integer pageNum, @RequestParam(value = "limit")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        LuiTableEntity luiTableEntity = new LuiTableEntity<MaterialStoreView>();
        PageInfo<SubmitOrderStyleProductMaterialsView> orderListView = new PageInfo<>(wareHouseService.getSubMaterialViewAll());
        List<SubmitOrderStyleProductMaterialsView> products = orderListView.getList();
        long total = orderListView.getTotal();
        if(products!=null&&products.size()>0){
            luiTableEntity.setCode("0");
            luiTableEntity.setMsg("查询成功");
            luiTableEntity.setCount(total);
            luiTableEntity.setData(products);
        }else{
            luiTableEntity.setCode("203");
            luiTableEntity.setMsg("查询失败");

        }
        return   luiTableEntity;
    }
    @RequestMapping("updatelMaterials")
    @ResponseBody
    public int updatelMaterials(Long id) {
        return wareHouseService.updatelMaterials(id);
    }
    @RequestMapping("updatOrderAuditStatus")
    @ResponseBody
    public int updatOrderAuditStatus(Long orderId) {
        return wareHouseService.updatOrderAuditStatus(orderId);
    }

    @RequestMapping("addInventory")
    public HashMap<String, String> addInventory(@RequestBody Inventory inventory) {
        return wareHouseService.addInventory(inventory);
    }

    @RequestMapping("queryInventory")
    public HashMap<String,String> queryInventory(Long  orderId) {
        return wareHouseService.queryInventory(orderId);
    }
    @RequestMapping("getSearchValue")
    @ResponseBody
    public List<WarehouseStoreAreaBatchView> getOrderFrom(String searchValue){return wareHouseService.queryByName(searchValue);}

}
